package cache

import "time"

type Mode int

const (
	Writable Mode = iota
	ReadOnly
)

type Options struct {
	MaxCount       int
	Mode           Mode
	ShardLen       int
	ExpireInterval time.Duration
	OnEvicted      func(string, interface{})
}

const defaultMaxCount = 20

type Option func(options *Options)

func loadOptions(options ...Option) *Options {
	opts := new(Options)
	for _, option := range options {
		option(opts)
	}
	return opts
}

func WithMaxCountOption(maxCount int) Option {
	return func(options *Options) {
		options.MaxCount = maxCount
	}
}

func WithModeOption(mode Mode) Option {
	return func(options *Options) {
		options.Mode = mode
	}
}

func WithOnEvicted(onEvicted func(string, interface{})) Option {
	return func(options *Options) {
		options.OnEvicted = onEvicted
	}
}

func repair(opts *Options) {
	if opts.MaxCount == 0 {
		opts.MaxCount = defaultMaxCount
	}
}
